package com.glink.manage.common;

import cn.hutool.core.bean.copier.BeanCopier;
import cn.hutool.core.bean.copier.CopyOptions;

import java.util.function.Supplier;

public class BeanKit {

    public static void copyProperties(Object source, Object target, CopyOptions options) {
        BeanCopier.create(source, target, options).copy();
    }

    public static void copyProperties(Object source, Object target) {
        copyProperties(source, target, CopyOptions.create());
    }

    public static <E> E copyProperties(Object source, Supplier<E> supplier) {
        final E bean = supplier.get();
        copyProperties(source, bean);
        return bean;
    }

    public static void copyPropertiesIgnoreNull(Object source, Object target) {
        copyProperties(source, target, CopyOptions.create().setIgnoreNullValue(true));
    }

    public static <E> E copyPropertiesIgnoreNull(Object source, Supplier<E> supplier) {
        final E bean = supplier.get();
        copyPropertiesIgnoreNull(source, bean);
        return bean;
    }

    public static void copyPropertiesIgnoreCase(Object source, Object target) {
        copyProperties(source, target, CopyOptions.create().setIgnoreCase(true));
    }

    public static <E> E copyPropertiesIgnoreCase(Object source, Supplier<E> supplier) {
        final E bean = supplier.get();
        copyPropertiesIgnoreCase(source, bean);
        return bean;
    }

}